import { defineStore } from 'pinia';
import Tool from "@/libs/tool";

export const useCategory = defineStore('category', {
    state: () => ({
        category: {
            list: [],
            expiryTime: 0, // 这里用来存储到期时间
        }
    }),
    getters: {
        getCategory: state => state.category
    },
    actions: {
        updateCategoryList(val) {
            this.category.list = val;
            this.category.expiryTime = Tool.getTimestamp() + 60 * 5;
            console.log("updateCategoryList:", val)
        }
    },
    storeOptions: {
        openStorage: true,
        storageWay: {
            setStorageWay: (key, data) => uni.setStorageSync(key, data), // 这里将存储方法替换
            getStorageWay: (key) => uni.getStorageSync(key),
        },
        paths:['category']
    }
});
